home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / winsrc17.zip / PROFILE.C < prev    next >
C/C++ Source or Header  |  1991-08-06  |  3KB  |  139 lines

  1. #include <windows.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "winfract.h"
  5. #include "profile.h"
  6.  
  7. extern int xdots, ydots, Sizing;
  8. extern int ZoomBarOpen, CoordBoxOpen;
  9.  
  10. static char None[]      = "None";
  11. static char SSTools[80];
  12. static char True[]      = "True";
  13. static char False[]     = "False";
  14. static char Yes[]       = "Yes";
  15. static char One[]       = "1";
  16.  
  17. static BOOL NoSave = FALSE;
  18.  
  19. char Winfract[]  = "Winfract";
  20. char Fractint[]  = "Fractint";
  21. char *ProgStr = Winfract;
  22.  
  23. void SetToolsPath(void) {
  24.    static char FileName[] = "sstools.ini";
  25.  
  26.    findpath(FileName, SSTools);
  27.    if(!*SSTools)
  28.       strcpy(SSTools, FileName);
  29. }
  30.  
  31. BOOL GetParamSwitch(char *Key) {
  32.    char Text[80];
  33.  
  34.    GetPrivateProfileString(ProgStr, Key, None, Text, sizeof(Text), SSTools);
  35.    if(!stricmp(Text, True) ||
  36.       !stricmp(Text, Yes) ||
  37.       !stricmp(Text, One)
  38.    ) return(TRUE);
  39.    return(FALSE);
  40. }
  41.  
  42. double GetFloatParam(char *Key, double Def) {
  43.    char Text[80];
  44.  
  45.    GetPrivateProfileString(ProgStr, Key, None, Text, sizeof(Text), SSTools);
  46.    if(!stricmp(None, Text))
  47.       return(Def);
  48.    return(atof(Text));
  49. }
  50.  
  51. double GetIntParam(char *Key, int Def) {
  52.    char Text[80];
  53.  
  54.    GetPrivateProfileString(ProgStr, Key, None, Text, sizeof(Text), SSTools);
  55.    if(!stricmp(None, Text))
  56.       return(Def);
  57.    return(atoi(Text));
  58. }
  59.  
  60. void SaveParamStr(char *Key, char *Str) {
  61.    if(!NoSave)
  62.       WritePrivateProfileString(ProgStr, Key, Str, SSTools);
  63. }
  64.  
  65. void SaveFloatParam(char *Key, double Num) {
  66.    char Str[80];
  67.  
  68.    sprintf(Str, "%g", Num);
  69.    SaveParamStr(Key, Str);
  70. }
  71.  
  72. void SaveIntParam(char *Key, int Num) {
  73.    char Str[80];
  74.  
  75.    sprintf(Str, "%d", Num);
  76.    SaveParamStr(Key, Str);
  77. }
  78.  
  79. void SaveParamSwitch(char *Key, BOOL Flag) {
  80.    char *Str;
  81.  
  82.    if(Flag)
  83.       Str = True;
  84.    else
  85.       Str = False;
  86.    SaveParamStr(Key, Str);
  87. }
  88.  
  89. void PositionWindow(HWND hWnd, char *Key) {
  90.    char Text[80];
  91.    POINT Pos;
  92.  
  93.    GetPrivateProfileString(Winfract, Key, None, Text, sizeof(Text), SSTools);
  94.    if(stricmp(Text, None)) {
  95.       sscanf(Text, "%d, %d", &Pos.x, &Pos.y);
  96.       NoSave = TRUE;
  97.       SetWindowPos(hWnd, GetNextWindow(hWnd, GW_HWNDPREV), Pos.x, Pos.y,
  98.                    0, 0, SWP_NOSIZE);
  99.       NoSave = FALSE;
  100.    }
  101. }
  102.  
  103. void SaveWindowPosition(HWND hWnd, char *Key) {
  104.    char Text[80];
  105.    RECT Rect;
  106.  
  107.    GetWindowRect(hWnd, &Rect);
  108.    sprintf(Text, "%d, %d", Rect.left, Rect.top);
  109.    SaveParamStr(Key, Text);
  110. }
  111.  
  112. char WindowSizingStr[]     = "WindowSizing";
  113. char ImageWidthStr[]       = "ImageWidth";
  114. char ImageHeightStr[]      = "ImageHeight";
  115. char ZoomBoxStr[]          = "ZoomBoxOpen";
  116. char CoordBoxStr[]         = "CoordinateBoxOpen";
  117. char WinfractPosStr[]      = "WinfractPosition";
  118. char ZoomBoxPosStr[]       = "ZoomBoxPosition";
  119. char CoordBoxPosStr[]      = "CoordBoxPosition";
  120.  
  121. void InitializeParameters(HWND hWnd) {
  122.    NoSave = TRUE;
  123.  
  124.    xdots = GetIntParam(ImageWidthStr, 200);
  125.    ydots = GetIntParam(ImageHeightStr, 150);
  126.  
  127.    PositionWindow(hWnd, WinfractPosStr);
  128.    if(GetParamSwitch(WindowSizingStr) != Sizing)
  129.       WindowSizing(hWnd);
  130.    if(GetParamSwitch(ZoomBoxStr) != ZoomBarOpen)
  131.       ZoomBar(hWnd);
  132.    if(GetParamSwitch(CoordBoxStr) != CoordBoxOpen)
  133.       CoordinateBox(hWnd);
  134.    NoSave = FALSE;
  135. }
  136.  
  137. void SaveParameters(HWND hWnd) {
  138. }
  139.